package com.whli.autumn.mall.wms.domain.vo.stock;

import com.whli.autumn.core.extend.domain.vo.BaseVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import java.math.BigDecimal;

/**
 * <p>库存信息VO</p>
 *
 * @author whli
 * @version 1.0.0
 * @since 2023-04-09 08:37
 */
@ApiModel(description = "库存信息VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class StockVO extends BaseVO {

	@ApiModelProperty(value = "仓库编码")
	private String warehouseInfoCode;

	@ApiModelProperty(value = "仓库名称")
	private String warehouseInfoName;

	@ApiModelProperty(value = "库区编码")
	private String warehouseAreaCode;

	@ApiModelProperty(value = "库区名称")
	private String warehouseAreaName;

	@ApiModelProperty(value = "库位编码")
	private String warehouseLocationCode;

	@ApiModelProperty(value = "库位描述")
	private String warehouseLocationName;

	@ApiModelProperty(value = "仓库分类")
	private String warehouseCategory;

	@ApiModelProperty(value = "仓库属性")
	private String warehouseProperty;

	@ApiModelProperty(value = "库存数量")
	private BigDecimal stockQty;

	@ApiModelProperty(value = "占用数量")
	private BigDecimal occupiedQty;

	/*----------------------------------------- 额外字段 ------------------------------------------------------*/

	@ApiModelProperty(value = "可用库存")
	private BigDecimal availableStock;

	public BigDecimal getAvailableStock() {
		BigDecimal tempStockQty = BigDecimal.ZERO;
		if (this.stockQty != null) {
			tempStockQty = this.stockQty;
		}
		BigDecimal tempOccupiedQty = BigDecimal.ZERO;
		if (this.occupiedQty != null) {
			tempOccupiedQty = this.occupiedQty;
		}
		if (tempOccupiedQty.compareTo(tempStockQty) >= 0) {
			return BigDecimal.ZERO;
		}
		return tempStockQty.subtract(tempOccupiedQty).setScale(2, BigDecimal.ROUND_HALF_UP);
	}

}
